package cs4280.ass2.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import cs4280.ass2.entity.User;

public class httpUtils {
	
	public static boolean isLogined(HttpServletRequest req){
		return (getLoginUser(req) != null);
	}
	public static User getLoginUser(HttpServletRequest req){
		HttpSession session = req.getSession();
		if(session.getAttribute("loggedInUser") !=null){
			return ((User)session.getAttribute("loggedInUser"));
		}
		return null;
	}
	public static long getLoginUserId(HttpServletRequest req){
		User user = getLoginUser(req);
		return (user != null) ? user.getId() : 0;
	}
}
